package com.ssy.lingxi.report.serviceimpl.tally;

import com.ssy.lingxi.report.api.enums.*;
import com.ssy.lingxi.report.api.vo.request.OperateNoticeVO;
import com.ssy.lingxi.report.dao.aftersale.RepairGoodsDAO;
import com.ssy.lingxi.report.dao.aftersale.ReplaceGoodsDAO;
import com.ssy.lingxi.report.dao.aftersale.ReturnGoodsDAO;
import com.ssy.lingxi.report.entity.report.MemberTallyReportDO;
import com.ssy.lingxi.report.model.bo.MemberTallyReportBO;
import com.ssy.lingxi.report.model.bo.StatisticsCountBO;
import com.ssy.lingxi.report.model.bo.tally.*;
import com.ssy.lingxi.report.model.bo.tally.statistics.*;
import com.ssy.lingxi.report.model.vo.response.AfterSaleTallyReportVO;
import com.ssy.lingxi.report.model.vo.response.TallyReportItemVO;
import com.ssy.lingxi.report.service.tally.IAfterSaleTallyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 售后计数接口实现
 * @author 伍将
 * @date 2020/11/21
 * @version 2.0.0
 */
@Service
public class AfterSaleTallyServiceImpl implements IAfterSaleTallyService {

    private static final Logger logger = LoggerFactory.getLogger(AfterSaleTallyServiceImpl.class);

    @Resource
    private RepairGoodsDAO repairGoodsDAO;
    @Resource
    private ReplaceGoodsDAO replaceGoodsDAO;
    @Resource
    private ReturnGoodsDAO returnGoodsDAO;

    /**
     * 转换售后
     * @param reportBO 计数报表
     * @return 售后计数报表
     */
    @Override
    public AfterSaleTallyReportVO convertAfterSaleTally(MemberTallyReportBO reportBO) {
        AfterSaleTallyReportVO result = new AfterSaleTallyReportVO();
        // 转换售后维修申请数据
        result.setRepairApplyList(convertAfterSaleRepairApplyTally(reportBO.getAfterSaleRepairApply()));
        // 转换售后维修维修数据
        result.setRepairHandleList(convertAfterSaleRepairHandleTally(reportBO.getAfterSaleRepairHandle()));
        // 转换售后换货申请数据
        result.setReplaceApplyList(convertAfterSaleReplaceApplyTally(reportBO.getAfterSaleReplaceApply()));
        // 转换售后换货维修数据
        result.setReplaceHandleList(convertAfterSaleReplaceHandleTally(reportBO.getAfterSaleReplaceHandle()));
        // 转换售后退货申请数据
        result.setReturnApplyList(convertAfterSaleReturnApplyTally(reportBO.getAfterSaleReturnApply()));
        // 转换售后退货处理数据
        result.setReturnHandleList(convertAfterSaleReturnHandleTally(reportBO.getAfterSaleReturnHandle()));

        return result;
    }

    /**
     * 转换售后维修申请数据
     * @param tallyBO 计数报表
     * @return 计数报表项
     */
    private List<TallyReportItemVO> convertAfterSaleRepairApplyTally(AfterSaleRepairApplyTallyBO tallyBO) {

        if (tallyBO == null) {
            tallyBO = new AfterSaleRepairApplyTallyBO();
        }

        List<TallyReportItemVO> resultList = new ArrayList<>();
        // 待提交
        TallyReportItemVO tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeCommitCount() > 0 ? tallyBO.getToBeCommitCount() : 0);
        tallyReportItem.setName(AfterSaleRepairApplyOperateTypeEnum.TO_BE_COMMIT.getName());
        tallyReportItem.setLink(AfterSaleRepairApplyOperateTypeEnum.TO_BE_COMMIT.getLink());
        resultList.add(tallyReportItem);
        // 待确认完成数
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeConfirmCompleteCount() > 0 ? tallyBO.getToBeConfirmCompleteCount() : 0);
        tallyReportItem.setName(AfterSaleRepairApplyOperateTypeEnum.TO_BE_CONFIRM_COMPLETE.getName());
        tallyReportItem.setLink(AfterSaleRepairApplyOperateTypeEnum.TO_BE_CONFIRM_COMPLETE.getLink());
        resultList.add(tallyReportItem);

        return resultList;
    }

    /**
     * 转换售后维修处理数据
     * @param tallyBO 计数报表
     * @return 计数报表项
     */
    private List<TallyReportItemVO> convertAfterSaleRepairHandleTally(AfterSaleRepairHandleTallyBO tallyBO) {
        if (tallyBO == null) {
            tallyBO = new AfterSaleRepairHandleTallyBO();
        }
        List<TallyReportItemVO> resultList = new ArrayList<>();
        // 待提交审核
        TallyReportItemVO tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeCommitValifyCount() > 0 ? tallyBO.getToBeCommitValifyCount() : 0);
        tallyReportItem.setName(AfterSaleRepairHandleOperateTypeEnum.TO_BE_VALIFY_COMMIT.getName());
        tallyReportItem.setLink(AfterSaleRepairHandleOperateTypeEnum.TO_BE_VALIFY_COMMIT.getLink());
        resultList.add(tallyReportItem);
        // 待一级审核
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeValifyStep1Count() > 0 ? tallyBO.getToBeValifyStep1Count() : 0);
        tallyReportItem.setName(AfterSaleRepairHandleOperateTypeEnum.TO_BE_VALIFY_STEP1.getName());
        tallyReportItem.setLink(AfterSaleRepairHandleOperateTypeEnum.TO_BE_VALIFY_STEP1.getLink());
        resultList.add(tallyReportItem);
        // 待二级审核
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeValifyStep2Count() > 0 ? tallyBO.getToBeValifyStep2Count() : 0);
        tallyReportItem.setName(AfterSaleRepairHandleOperateTypeEnum.TO_BE_VALIFY_STEP2.getName());
        tallyReportItem.setLink(AfterSaleRepairHandleOperateTypeEnum.TO_BE_VALIFY_STEP2.getLink());
        resultList.add(tallyReportItem);
        // 待确认审核结果
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeConfirmCount() > 0 ? tallyBO.getToBeConfirmCount() : 0);
        tallyReportItem.setName(AfterSaleRepairHandleOperateTypeEnum.TO_BE_CONFIRM.getName());
        tallyReportItem.setLink(AfterSaleRepairHandleOperateTypeEnum.TO_BE_CONFIRM.getLink());
        resultList.add(tallyReportItem);

        return resultList;
    }

    /**
     * 转换售后换货处理数据
     * @param tallyBO 计数报表
     * @return 计数报表项
     */
    private List<TallyReportItemVO> convertAfterSaleReplaceHandleTally(AfterSaleReplaceHandleTallyBO tallyBO) {
        List<TallyReportItemVO> resultList = new ArrayList<>();
        if (tallyBO == null) {
            tallyBO = new AfterSaleReplaceHandleTallyBO();
        }
        // 待提交审核
        TallyReportItemVO tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeCommitValifyCount() > 0 ? tallyBO.getToBeCommitValifyCount() : 0);
        tallyReportItem.setName(AfterSaleReplaceHandleOperateTypeEnum.TO_BE_VALIFY_COMMIT.getName());
        tallyReportItem.setLink(AfterSaleReplaceHandleOperateTypeEnum.TO_BE_VALIFY_COMMIT.getLink());
        resultList.add(tallyReportItem);
        // 待审核换货申请单（一级）
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeValifyStep1Count() > 0 ? tallyBO.getToBeValifyStep1Count() : 0);
        tallyReportItem.setName(AfterSaleReplaceHandleOperateTypeEnum.TO_BE_VALIFY_STEP1.getName());
        tallyReportItem.setLink(AfterSaleReplaceHandleOperateTypeEnum.TO_BE_VALIFY_STEP1.getLink());
        resultList.add(tallyReportItem);
        // 待审核换货申请单（二级）
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeValifyStep2Count() > 0 ? tallyBO.getToBeValifyStep2Count() : 0);
        tallyReportItem.setName(AfterSaleReplaceHandleOperateTypeEnum.TO_BE_VALIFY_STEP2.getName());
        tallyReportItem.setLink(AfterSaleReplaceHandleOperateTypeEnum.TO_BE_VALIFY_STEP2.getLink());
        resultList.add(tallyReportItem);
        // 待确认数
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeConfirmCount() > 0 ? tallyBO.getToBeConfirmCount() : 0);
        tallyReportItem.setName(AfterSaleReplaceHandleOperateTypeEnum.TO_BE_CONFIRM.getName());
        tallyReportItem.setLink(AfterSaleReplaceHandleOperateTypeEnum.TO_BE_CONFIRM.getLink());
        resultList.add(tallyReportItem);
        // 待新增退货入库
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeAddStorageCount() > 0 ? tallyBO.getToBeAddStorageCount() : 0);
        tallyReportItem.setName(AfterSaleReplaceHandleOperateTypeEnum.TO_BE_ADD_STORAGE.getName());
        tallyReportItem.setLink(AfterSaleReplaceHandleOperateTypeEnum.TO_BE_ADD_STORAGE.getLink());
        resultList.add(tallyReportItem);
        // 待退货收货
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeReceiveCount() > 0 ? tallyBO.getToBeReceiveCount() : 0);
        tallyReportItem.setName(AfterSaleReplaceHandleOperateTypeEnum.TO_BE_RECEIVE.getName());
        tallyReportItem.setLink(AfterSaleReplaceHandleOperateTypeEnum.TO_BE_RECEIVE.getLink());
        resultList.add(tallyReportItem);
        // 待新增退货发货单
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeAddDeliveryCount() > 0 ? tallyBO.getToBeAddDeliveryCount() : 0);
        tallyReportItem.setName(AfterSaleReplaceHandleOperateTypeEnum.TO_BE_ADD_DELIVERY.getName());
        tallyReportItem.setLink(AfterSaleReplaceHandleOperateTypeEnum.TO_BE_ADD_DELIVERY.getLink());
        resultList.add(tallyReportItem);
        // 待新增物流
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeAddLogisticsCount() > 0 ? tallyBO.getToBeAddLogisticsCount() : 0);
        tallyReportItem.setName(AfterSaleReplaceHandleOperateTypeEnum.TO_BE_ADD_LOGISTICS.getName());
        tallyReportItem.setLink(AfterSaleReplaceHandleOperateTypeEnum.TO_BE_ADD_LOGISTICS.getLink());
        resultList.add(tallyReportItem);
        // 待换货发货
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeDeliveryCount() > 0 ? tallyBO.getToBeDeliveryCount() : 0);
        tallyReportItem.setName(AfterSaleReplaceHandleOperateTypeEnum.TO_BE_DELIVERY.getName());
        tallyReportItem.setLink(AfterSaleReplaceHandleOperateTypeEnum.TO_BE_DELIVERY.getLink());
        resultList.add(tallyReportItem);
        // 待确认换货回单
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeConfirmReceiptCount() > 0 ? tallyBO.getToBeConfirmReceiptCount() : 0);
        tallyReportItem.setName(AfterSaleReplaceHandleOperateTypeEnum.TO_BE_CONFIRM_RECEIPT.getName());
        tallyReportItem.setLink(AfterSaleReplaceHandleOperateTypeEnum.TO_BE_CONFIRM_RECEIPT.getLink());
        resultList.add(tallyReportItem);


        return resultList;
    }

    /**
     * 转换售后换货申请数据
     * @param tallyBO 计数报表
     * @return 计数报表项
     */
    private List<TallyReportItemVO> convertAfterSaleReplaceApplyTally(AfterSaleReplaceApplyTallyBO tallyBO) {
        List<TallyReportItemVO> resultList = new ArrayList<>();
        if (tallyBO == null) {
            tallyBO = new AfterSaleReplaceApplyTallyBO();
        }

        // 待提交
        TallyReportItemVO tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeCommitCount() > 0 ? tallyBO.getToBeCommitCount() : 0);
        tallyReportItem.setName(AfterSaleReplaceApplyOperateTypeEnum.TO_BE_COMMIT.getName());
        tallyReportItem.setLink(AfterSaleReplaceApplyOperateTypeEnum.TO_BE_COMMIT.getLink());
        resultList.add(tallyReportItem);
        // 待新增退货发货单
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeAddDeliveryCount() > 0 ? tallyBO.getToBeAddDeliveryCount() : 0);
        tallyReportItem.setName(AfterSaleReplaceApplyOperateTypeEnum.TO_BE_ADD_DELIVERY.getName());
        tallyReportItem.setLink(AfterSaleReplaceApplyOperateTypeEnum.TO_BE_ADD_DELIVERY.getLink());
        resultList.add(tallyReportItem);
        // 待确认物流单
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeConfirmLogisticsCount() > 0 ? tallyBO.getToBeConfirmLogisticsCount() : 0);
        tallyReportItem.setName(AfterSaleReplaceApplyOperateTypeEnum.TO_BE_CONFIRM_LOGISTICS.getName());
        tallyReportItem.setLink(AfterSaleReplaceApplyOperateTypeEnum.TO_BE_CONFIRM_LOGISTICS.getLink());
        resultList.add(tallyReportItem);
        // 待退货发货
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeDeliveryCount() > 0 ? tallyBO.getToBeDeliveryCount() : 0);
        tallyReportItem.setName(AfterSaleReplaceApplyOperateTypeEnum.TO_BE_DELIVERY.getName());
        tallyReportItem.setLink(AfterSaleReplaceApplyOperateTypeEnum.TO_BE_DELIVERY.getLink());
        resultList.add(tallyReportItem);
        // 待确认退货回单
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeConfirmReceiptCount() > 0 ? tallyBO.getToBeConfirmReceiptCount() : 0);
        tallyReportItem.setName(AfterSaleReplaceApplyOperateTypeEnum.TO_BE_CONFIRM_RECEIPT.getName());
        tallyReportItem.setLink(AfterSaleReplaceApplyOperateTypeEnum.TO_BE_CONFIRM_RECEIPT.getLink());
        resultList.add(tallyReportItem);
        // 待新增换货入库单
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeAddStorageCount() > 0 ? tallyBO.getToBeAddStorageCount() : 0);
        tallyReportItem.setName(AfterSaleReplaceApplyOperateTypeEnum.TO_BE_ADD_STORAGE.getName());
        tallyReportItem.setLink(AfterSaleReplaceApplyOperateTypeEnum.TO_BE_ADD_STORAGE.getLink());
        resultList.add(tallyReportItem);
        // 待换货收货
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeReceiveCount() > 0 ? tallyBO.getToBeReceiveCount() : 0);
        tallyReportItem.setName(AfterSaleReplaceApplyOperateTypeEnum.TO_BE_RECEIVE.getName());
        tallyReportItem.setLink(AfterSaleReplaceApplyOperateTypeEnum.TO_BE_RECEIVE.getLink());
        resultList.add(tallyReportItem);
        // 待确认售后完成
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeConfirmCompleteCount() > 0 ? tallyBO.getToBeConfirmCompleteCount() : 0);
        tallyReportItem.setName(AfterSaleReplaceApplyOperateTypeEnum.TO_BE_CONFIRM_COMPLETE.getName());
        tallyReportItem.setLink(AfterSaleReplaceApplyOperateTypeEnum.TO_BE_CONFIRM_COMPLETE.getLink());
        resultList.add(tallyReportItem);

        return resultList;
    }

    /**
     * 转换售后退货申请数据
     * @param tallyBO 计数报表
     * @return 计数报表项
     */
    private List<TallyReportItemVO> convertAfterSaleReturnApplyTally(AfterSaleReturnApplyTallyBO tallyBO) {
        List<TallyReportItemVO> resultList = new ArrayList<>();
        if (tallyBO == null) {
            tallyBO = new AfterSaleReturnApplyTallyBO();
        }
        // 待提交
        TallyReportItemVO tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeCommitCount());
        tallyReportItem.setName(AfterSaleReturnApplyOperateTypeEnum.TO_BE_COMMIT.getName());
        tallyReportItem.setLink(AfterSaleReturnApplyOperateTypeEnum.TO_BE_COMMIT.getLink());
        resultList.add(tallyReportItem);
        // 待新增退货发货单
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeAddDeliveryCount());
        tallyReportItem.setName(AfterSaleReturnApplyOperateTypeEnum.TO_BE_ADD_DELIVERY.getName());
        tallyReportItem.setLink(AfterSaleReturnApplyOperateTypeEnum.TO_BE_ADD_DELIVERY.getLink());
        resultList.add(tallyReportItem);
        // 待新增物流单
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeAddLogisticsCount());
        tallyReportItem.setName(AfterSaleReturnApplyOperateTypeEnum.TO_BE_ADD_LOGISTICS.getName());
        tallyReportItem.setLink(AfterSaleReturnApplyOperateTypeEnum.TO_BE_ADD_LOGISTICS.getLink());
        resultList.add(tallyReportItem);
        // 待退货发货
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeDeliveryCount());
        tallyReportItem.setName(AfterSaleReturnApplyOperateTypeEnum.TO_BE_DELIVERY.getName());
        tallyReportItem.setLink(AfterSaleReturnApplyOperateTypeEnum.TO_BE_DELIVERY.getLink());
        resultList.add(tallyReportItem);
        // 待确认退货回单
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeConfirmReceiptCount());
        tallyReportItem.setName(AfterSaleReturnApplyOperateTypeEnum.TO_BE_CONFIRM_RECEIPT.getName());
        tallyReportItem.setLink(AfterSaleReturnApplyOperateTypeEnum.TO_BE_CONFIRM_RECEIPT.getLink());
        resultList.add(tallyReportItem);
        // 待确认退款结果
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeConfirmRefundCount());
        tallyReportItem.setName(AfterSaleReturnApplyOperateTypeEnum.TO_BE_CONFIRM_REFUND.getName());
        tallyReportItem.setLink(AfterSaleReturnApplyOperateTypeEnum.TO_BE_CONFIRM_REFUND.getLink());
        resultList.add(tallyReportItem);
        // 待确认售后完成
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeConfirmCompleteCount());
        tallyReportItem.setName(AfterSaleReturnApplyOperateTypeEnum.TO_BE_CONFIRM_COMPLETE.getName());
        tallyReportItem.setLink(AfterSaleReturnApplyOperateTypeEnum.TO_BE_CONFIRM_COMPLETE.getLink());
        resultList.add(tallyReportItem);

        resultList.forEach(o -> o.setCount(o.getCount() > 0 ? o.getCount() : 0));

        return resultList;
    }

    /**
     * 转换售后退货处理数据
     * @param tallyBO 计数报表
     * @return 计数报表项
     */
    private List<TallyReportItemVO> convertAfterSaleReturnHandleTally(AfterSaleReturnHandleTallyBO tallyBO) {
        List<TallyReportItemVO> resultList = new ArrayList<>();
        if (tallyBO == null) {
            tallyBO = new AfterSaleReturnHandleTallyBO();
        }

        // 待提交审核
        TallyReportItemVO tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeCommitValifyCount());
        tallyReportItem.setName(AfterSaleReturnHandleOperateTypeEnum.TO_BE_VALIFY_COMMIT.getName());
        tallyReportItem.setLink(AfterSaleReturnHandleOperateTypeEnum.TO_BE_VALIFY_COMMIT.getLink());
        resultList.add(tallyReportItem);
        // 待审核换货申请单（一级）
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeValifyStep1Count());
        tallyReportItem.setName(AfterSaleReturnHandleOperateTypeEnum.TO_BE_VALIFY_STEP1.getName());
        tallyReportItem.setLink(AfterSaleReturnHandleOperateTypeEnum.TO_BE_VALIFY_STEP1.getLink());
        resultList.add(tallyReportItem);
        // 待审核换货申请单（二级）
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeValifyStep2Count());
        tallyReportItem.setName(AfterSaleReturnHandleOperateTypeEnum.TO_BE_VALIFY_STEP2.getName());
        tallyReportItem.setLink(AfterSaleReturnHandleOperateTypeEnum.TO_BE_VALIFY_STEP2.getLink());
        resultList.add(tallyReportItem);
        // 待确认数
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeConfirmCount());
        tallyReportItem.setName(AfterSaleReturnHandleOperateTypeEnum.TO_BE_CONFIRM.getName());
        tallyReportItem.setLink(AfterSaleReturnHandleOperateTypeEnum.TO_BE_CONFIRM.getLink());
        resultList.add(tallyReportItem);
        // 待新增退货入库
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeAddStorageCount());
        tallyReportItem.setName(AfterSaleReturnHandleOperateTypeEnum.TO_BE_ADD_STORAGE.getName());
        tallyReportItem.setLink(AfterSaleReturnHandleOperateTypeEnum.TO_BE_ADD_STORAGE.getLink());
        resultList.add(tallyReportItem);
        // 待退货收货
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeReceiveCount());
        tallyReportItem.setName(AfterSaleReturnHandleOperateTypeEnum.TO_BE_RECEIVE.getName());
        tallyReportItem.setLink(AfterSaleReturnHandleOperateTypeEnum.TO_BE_RECEIVE.getLink());
        resultList.add(tallyReportItem);
        // 待退款
        tallyReportItem = new TallyReportItemVO();
        tallyReportItem.setCount(tallyBO.getToBeRefundCount());
        tallyReportItem.setName(AfterSaleReturnHandleOperateTypeEnum.TO_BE_REFUND.getName());
        tallyReportItem.setLink(AfterSaleReturnHandleOperateTypeEnum.TO_BE_REFUND.getLink());
        resultList.add(tallyReportItem);

        resultList.forEach(o -> o.setCount(o.getCount() > 0 ? o.getCount() : 0));

        return resultList;
    }

    /**
     * 设置售后
     * @param tallyReportBO 会员计数报表
     * @param noticeVO 操作通知VO
     * @return 会员计数报表
     */
    @Override
    public MemberTallyReportBO setAfterSaleTally(MemberTallyReportBO tallyReportBO, OperateNoticeVO noticeVO) {

        OperateDataSourceEnum sourceEnum = OperateDataSourceEnum.getEnum(noticeVO.getDataSource());
        switch (sourceEnum) {
            case AFTER_SALE_REPAIR_APPLY: // 转换售后维修申请数据
                tallyReportBO.setAfterSaleRepairApply(setAfterSaleRepairApplyTally(tallyReportBO.getAfterSaleRepairApply(), noticeVO));
                break;
            case AFTER_SALE_REPAIR_HANDLE: // 转换售后维修维修数据
                tallyReportBO.setAfterSaleRepairHandle(setAfterSaleRepairHandleTally(tallyReportBO.getAfterSaleRepairHandle(), noticeVO));
                break;
            case AFTER_SALE_REPLACE_APPLY: // 转换售后换货申请数据
                tallyReportBO.setAfterSaleReplaceApply(setAfterSaleReplaceApplyTally(tallyReportBO.getAfterSaleReplaceApply(), noticeVO));
                break;
            case AFTER_SALE_REPLACE_HANDLE: // 转换售后换货维修数据
                tallyReportBO.setAfterSaleReplaceHandle(setAfterSaleReplaceHandleTally(tallyReportBO.getAfterSaleReplaceHandle(), noticeVO));
                break;
            case AFTER_SALE_RETURN_APPLY: // 转换售后退货申请数据
                tallyReportBO.setAfterSaleReturnApply(setAfterSaleReturnApplyTally(tallyReportBO.getAfterSaleReturnApply(), noticeVO));
                break;
            case AFTER_SALE_RETURN_HANDLE: // 设置售后退货处理数据
                tallyReportBO.setAfterSaleReturnHandle(setAfterSaleReturnHandleTally(tallyReportBO.getAfterSaleReturnHandle(), noticeVO));
                break;
        }
        return tallyReportBO;
    }

    /**
     * 设置售后退货处理数据
     * @param tallyBO
     * @param noticeVO
     * @return
     */
    private AfterSaleReturnHandleTallyBO setAfterSaleReturnHandleTally(AfterSaleReturnHandleTallyBO tallyBO, OperateNoticeVO noticeVO) {
        if (tallyBO == null) {
            tallyBO = new AfterSaleReturnHandleTallyBO();
        }

        // 更新数据
        AfterSaleReturnHandleOperateTypeEnum typeEnum;
        if (noticeVO.getReduceCount() > 0) {
            typeEnum = AfterSaleReturnHandleOperateTypeEnum.getEnum(noticeVO.getReduceOperateType());
            if (typeEnum != null) {
                switch (typeEnum) {
                    case TO_BE_VALIFY_COMMIT:
                        tallyBO.setToBeCommitValifyCount(tallyBO.getToBeCommitValifyCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_VALIFY_STEP1:
                        tallyBO.setToBeValifyStep1Count(tallyBO.getToBeValifyStep1Count() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_VALIFY_STEP2:
                        tallyBO.setToBeValifyStep2Count(tallyBO.getToBeValifyStep2Count() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_CONFIRM:
                        tallyBO.setToBeConfirmCount(tallyBO.getToBeConfirmCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_ADD_STORAGE:
                        tallyBO.setToBeAddStorageCount(tallyBO.getToBeAddStorageCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_RECEIVE:
                        tallyBO.setToBeReceiveCount(tallyBO.getToBeReceiveCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_REFUND:
                        tallyBO.setToBeRefundCount(tallyBO.getToBeRefundCount() - noticeVO.getReduceCount());
                        break;
                }
            }
        }
        if (noticeVO.getIncreaseCount() > 0) {
            typeEnum = AfterSaleReturnHandleOperateTypeEnum.getEnum(noticeVO.getIncreaseOperateType());
            if (typeEnum != null) {
                switch (typeEnum) {
                    case TO_BE_VALIFY_COMMIT:
                        tallyBO.setToBeCommitValifyCount(tallyBO.getToBeCommitValifyCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_VALIFY_STEP1:
                        tallyBO.setToBeValifyStep1Count(tallyBO.getToBeValifyStep1Count() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_VALIFY_STEP2:
                        tallyBO.setToBeValifyStep2Count(tallyBO.getToBeValifyStep2Count() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_CONFIRM:
                        tallyBO.setToBeConfirmCount(tallyBO.getToBeConfirmCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_ADD_STORAGE:
                        tallyBO.setToBeAddStorageCount(tallyBO.getToBeAddStorageCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_RECEIVE:
                        tallyBO.setToBeReceiveCount(tallyBO.getToBeReceiveCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_REFUND:
                        tallyBO.setToBeRefundCount(tallyBO.getToBeRefundCount() + noticeVO.getIncreaseCount());
                        break;
                }
            }
        }

        return tallyBO;
    }

    /**
     * 设置售后退货申请数据
     * @param tallyBO
     * @param noticeVO
     * @return
     */
    private AfterSaleReturnApplyTallyBO setAfterSaleReturnApplyTally(AfterSaleReturnApplyTallyBO tallyBO, OperateNoticeVO noticeVO) {
        if (tallyBO == null) {
            tallyBO = new AfterSaleReturnApplyTallyBO();
        }
        // 更新数据
        AfterSaleReturnApplyOperateTypeEnum typeEnum;
        if (noticeVO.getReduceCount() > 0) {
            typeEnum = AfterSaleReturnApplyOperateTypeEnum.getEnum(noticeVO.getReduceOperateType());
            if (typeEnum != null) {
                switch (typeEnum) {
                    case TO_BE_COMMIT:
                        tallyBO.setToBeCommitCount(tallyBO.getToBeCommitCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_ADD_DELIVERY:
                        tallyBO.setToBeAddDeliveryCount(tallyBO.getToBeAddDeliveryCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_ADD_LOGISTICS:
                        tallyBO.setToBeAddLogisticsCount(tallyBO.getToBeAddLogisticsCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_DELIVERY:
                        tallyBO.setToBeDeliveryCount(tallyBO.getToBeDeliveryCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_CONFIRM_RECEIPT:
                        tallyBO.setToBeConfirmReceiptCount(tallyBO.getToBeConfirmReceiptCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_CONFIRM_REFUND:
                        tallyBO.setToBeConfirmRefundCount(tallyBO.getToBeConfirmRefundCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_CONFIRM_COMPLETE:
                        tallyBO.setToBeConfirmCompleteCount(tallyBO.getToBeConfirmCompleteCount() - noticeVO.getReduceCount());
                        break;
                }
            }
        }
        if (noticeVO.getIncreaseCount() > 0) {
            typeEnum = AfterSaleReturnApplyOperateTypeEnum.getEnum(noticeVO.getIncreaseOperateType());
            if (typeEnum != null) {
                switch (typeEnum) {
                    case TO_BE_COMMIT:
                        tallyBO.setToBeCommitCount(tallyBO.getToBeCommitCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_ADD_DELIVERY:
                        tallyBO.setToBeAddDeliveryCount(tallyBO.getToBeAddDeliveryCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_ADD_LOGISTICS:
                        tallyBO.setToBeAddLogisticsCount(tallyBO.getToBeAddLogisticsCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_DELIVERY:
                        tallyBO.setToBeDeliveryCount(tallyBO.getToBeDeliveryCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_CONFIRM_RECEIPT:
                        tallyBO.setToBeConfirmReceiptCount(tallyBO.getToBeConfirmReceiptCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_CONFIRM_REFUND:
                        tallyBO.setToBeConfirmRefundCount(tallyBO.getToBeConfirmRefundCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_CONFIRM_COMPLETE:
                        tallyBO.setToBeConfirmCompleteCount(tallyBO.getToBeConfirmCompleteCount() + noticeVO.getIncreaseCount());
                        break;
                }
            }
        }

        return tallyBO;
    }

    /**
     * 设置售后换货申请数据
     * @param tallyBO
     * @param noticeVO
     * @return
     */
    private AfterSaleReplaceApplyTallyBO setAfterSaleReplaceApplyTally(AfterSaleReplaceApplyTallyBO tallyBO, OperateNoticeVO noticeVO) {
        if (tallyBO == null) {
            tallyBO = new AfterSaleReplaceApplyTallyBO();
        }
        // 更新数据
        AfterSaleReplaceApplyOperateTypeEnum typeEnum;
        if (noticeVO.getReduceCount() > 0) {
            typeEnum = AfterSaleReplaceApplyOperateTypeEnum.getEnum(noticeVO.getReduceOperateType());
            if (typeEnum != null) {
                switch (typeEnum) {
                    case TO_BE_COMMIT:
                        tallyBO.setToBeCommitCount(tallyBO.getToBeCommitCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_ADD_DELIVERY:
                        tallyBO.setToBeAddDeliveryCount(tallyBO.getToBeAddDeliveryCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_CONFIRM_LOGISTICS:
                        tallyBO.setToBeConfirmLogisticsCount(tallyBO.getToBeConfirmLogisticsCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_DELIVERY:
                        tallyBO.setToBeDeliveryCount(tallyBO.getToBeDeliveryCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_CONFIRM_RECEIPT:
                        tallyBO.setToBeConfirmReceiptCount(tallyBO.getToBeConfirmReceiptCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_ADD_STORAGE:
                        tallyBO.setToBeAddStorageCount(tallyBO.getToBeAddStorageCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_RECEIVE:
                        tallyBO.setToBeReceiveCount(tallyBO.getToBeReceiveCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_CONFIRM_COMPLETE:
                        tallyBO.setToBeConfirmCompleteCount(tallyBO.getToBeConfirmCompleteCount() - noticeVO.getReduceCount());
                        break;
                }
            }
        }
        if (noticeVO.getIncreaseCount() > 0) {
            typeEnum = AfterSaleReplaceApplyOperateTypeEnum.getEnum(noticeVO.getIncreaseOperateType());
            if (typeEnum != null) {
                switch (typeEnum) {
                    case TO_BE_COMMIT:
                        tallyBO.setToBeCommitCount(tallyBO.getToBeCommitCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_ADD_DELIVERY:
                        tallyBO.setToBeAddDeliveryCount(tallyBO.getToBeAddDeliveryCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_CONFIRM_LOGISTICS:
                        tallyBO.setToBeConfirmLogisticsCount(tallyBO.getToBeConfirmLogisticsCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_DELIVERY:
                        tallyBO.setToBeDeliveryCount(tallyBO.getToBeDeliveryCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_CONFIRM_RECEIPT:
                        tallyBO.setToBeConfirmReceiptCount(tallyBO.getToBeConfirmReceiptCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_ADD_STORAGE:
                        tallyBO.setToBeAddStorageCount(tallyBO.getToBeAddStorageCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_RECEIVE:
                        tallyBO.setToBeReceiveCount(tallyBO.getToBeReceiveCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_CONFIRM_COMPLETE:
                        tallyBO.setToBeConfirmCompleteCount(tallyBO.getToBeConfirmCompleteCount() + noticeVO.getIncreaseCount());
                        break;
                }
            }
        }

        return tallyBO;
    }

    /**
     * 设置售后换货处理数据
     * @param tallyBO
     * @param noticeVO
     * @return
     */
    private AfterSaleReplaceHandleTallyBO setAfterSaleReplaceHandleTally(AfterSaleReplaceHandleTallyBO tallyBO, OperateNoticeVO noticeVO) {
        if (tallyBO == null) {
            tallyBO = new AfterSaleReplaceHandleTallyBO();
        }
        // 更新数据
        AfterSaleReplaceHandleOperateTypeEnum typeEnum;
        if (noticeVO.getReduceCount() > 0) {
            typeEnum = AfterSaleReplaceHandleOperateTypeEnum.getEnum(noticeVO.getReduceOperateType());
            if (typeEnum != null) {
                switch (typeEnum) {
                    case TO_BE_VALIFY_COMMIT:
                        tallyBO.setToBeCommitValifyCount(tallyBO.getToBeCommitValifyCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_VALIFY_STEP1:
                        tallyBO.setToBeValifyStep1Count(tallyBO.getToBeValifyStep1Count() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_VALIFY_STEP2:
                        tallyBO.setToBeValifyStep2Count(tallyBO.getToBeValifyStep2Count() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_CONFIRM:
                        tallyBO.setToBeConfirmCount(tallyBO.getToBeConfirmCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_ADD_STORAGE:
                        tallyBO.setToBeAddStorageCount(tallyBO.getToBeAddStorageCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_RECEIVE:
                        tallyBO.setToBeReceiveCount(tallyBO.getToBeReceiveCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_ADD_DELIVERY:
                        tallyBO.setToBeAddDeliveryCount(tallyBO.getToBeAddDeliveryCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_ADD_LOGISTICS:
                        tallyBO.setToBeAddLogisticsCount(tallyBO.getToBeAddLogisticsCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_DELIVERY:
                        tallyBO.setToBeDeliveryCount(tallyBO.getToBeDeliveryCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_CONFIRM_RECEIPT:
                        tallyBO.setToBeConfirmReceiptCount(tallyBO.getToBeConfirmReceiptCount() - noticeVO.getReduceCount());
                        break;
                }
            }
        }
        if (noticeVO.getIncreaseCount() > 0) {
            typeEnum = AfterSaleReplaceHandleOperateTypeEnum.getEnum(noticeVO.getIncreaseOperateType());
            if (typeEnum != null) {
                switch (typeEnum) {
                    case TO_BE_VALIFY_COMMIT:
                        tallyBO.setToBeCommitValifyCount(tallyBO.getToBeCommitValifyCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_VALIFY_STEP1:
                        tallyBO.setToBeValifyStep1Count(tallyBO.getToBeValifyStep1Count() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_VALIFY_STEP2:
                        tallyBO.setToBeValifyStep2Count(tallyBO.getToBeValifyStep2Count() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_CONFIRM:
                        tallyBO.setToBeConfirmCount(tallyBO.getToBeConfirmCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_ADD_STORAGE:
                        tallyBO.setToBeAddStorageCount(tallyBO.getToBeAddStorageCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_RECEIVE:
                        tallyBO.setToBeReceiveCount(tallyBO.getToBeReceiveCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_ADD_DELIVERY:
                        tallyBO.setToBeAddDeliveryCount(tallyBO.getToBeAddDeliveryCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_ADD_LOGISTICS:
                        tallyBO.setToBeAddLogisticsCount(tallyBO.getToBeAddLogisticsCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_DELIVERY:
                        tallyBO.setToBeDeliveryCount(tallyBO.getToBeDeliveryCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_CONFIRM_RECEIPT:
                        tallyBO.setToBeConfirmReceiptCount(tallyBO.getToBeConfirmReceiptCount() + noticeVO.getIncreaseCount());
                        break;
                }
            }
        }

        return tallyBO;
    }

    /**
     * 设置售后维修申请数据
     * @param tallyBO
     * @param noticeVO
     * @return
     */
    private AfterSaleRepairApplyTallyBO setAfterSaleRepairApplyTally(AfterSaleRepairApplyTallyBO tallyBO, OperateNoticeVO noticeVO) {
        if (tallyBO == null) {
            tallyBO = new AfterSaleRepairApplyTallyBO();
        }
        // 更新数据
        AfterSaleRepairApplyOperateTypeEnum typeEnum;
        if (noticeVO.getReduceCount() > 0) {
            typeEnum = AfterSaleRepairApplyOperateTypeEnum.getEnum(noticeVO.getReduceOperateType());
            if (typeEnum != null) {
                switch (typeEnum) {
                    case TO_BE_COMMIT:
                        tallyBO.setToBeCommitCount(tallyBO.getToBeCommitCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_CONFIRM_COMPLETE:
                        tallyBO.setToBeConfirmCompleteCount(tallyBO.getToBeConfirmCompleteCount() - noticeVO.getReduceCount());
                        break;
                }
            }
        }
        if (noticeVO.getIncreaseCount() > 0) {
            typeEnum = AfterSaleRepairApplyOperateTypeEnum.getEnum(noticeVO.getIncreaseOperateType());
            if (typeEnum != null) {
                switch (typeEnum) {
                    case TO_BE_COMMIT:
                        tallyBO.setToBeCommitCount(tallyBO.getToBeCommitCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_CONFIRM_COMPLETE:
                        tallyBO.setToBeConfirmCompleteCount(tallyBO.getToBeConfirmCompleteCount() + noticeVO.getIncreaseCount());
                        break;
                }
            }
        }

        return tallyBO;
    }

    /**
     * 设置售后维修处理数据
     * @param tallyBO
     * @param noticeVO
     * @return
     */
    private AfterSaleRepairHandleTallyBO setAfterSaleRepairHandleTally(AfterSaleRepairHandleTallyBO tallyBO, OperateNoticeVO noticeVO) {
        if (tallyBO == null) {
            tallyBO = new AfterSaleRepairHandleTallyBO();
        }
        // 更新数据
        AfterSaleRepairHandleOperateTypeEnum typeEnum;
        if (noticeVO.getReduceCount() > 0) {
            typeEnum = AfterSaleRepairHandleOperateTypeEnum.getEnum(noticeVO.getReduceOperateType());
            if (typeEnum != null) {
                switch (typeEnum) {
                    case TO_BE_VALIFY_COMMIT:
                        tallyBO.setToBeCommitValifyCount(tallyBO.getToBeCommitValifyCount() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_VALIFY_STEP1:
                        tallyBO.setToBeValifyStep1Count(tallyBO.getToBeValifyStep1Count() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_VALIFY_STEP2:
                        tallyBO.setToBeValifyStep2Count(tallyBO.getToBeValifyStep2Count() - noticeVO.getReduceCount());
                        break;
                    case TO_BE_CONFIRM:
                        tallyBO.setToBeConfirmCount(tallyBO.getToBeConfirmCount() - noticeVO.getReduceCount());
                        break;
                }
            }
        }
        if (noticeVO.getIncreaseCount() > 0) {
            typeEnum = AfterSaleRepairHandleOperateTypeEnum.getEnum(noticeVO.getIncreaseOperateType());
            if (typeEnum != null) {
                switch (typeEnum) {
                    case TO_BE_VALIFY_COMMIT:
                        tallyBO.setToBeCommitValifyCount(tallyBO.getToBeCommitValifyCount() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_VALIFY_STEP1:
                        tallyBO.setToBeValifyStep1Count(tallyBO.getToBeValifyStep1Count() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_VALIFY_STEP2:
                        tallyBO.setToBeValifyStep2Count(tallyBO.getToBeValifyStep2Count() + noticeVO.getIncreaseCount());
                        break;
                    case TO_BE_CONFIRM:
                        tallyBO.setToBeConfirmCount(tallyBO.getToBeConfirmCount() + noticeVO.getIncreaseCount());
                        break;
                }
            }
        }

        return tallyBO;
    }

    /**
     * 统计计数
     * @param reportList
     * @return
     */
    @Override
    public List<MemberTallyReportDO> statisticsTally(List<MemberTallyReportDO> reportList) {

        // 维修申请
        reportList = statisticsRepairApplyTally(reportList);
        // 维修处理
        reportList = statisticsRepairHandleTally(reportList);

        // 换货申请
        reportList = statisticsReplaceApplyTally(reportList);
        // 换货处理
        reportList = statisticsReplaceHandleTally(reportList);

        // 退货申请
        reportList = statisticsReturnApplyTally(reportList);
        // 退货处理
        reportList = statisticsReturnHandleTally(reportList);

        return reportList;
    }

    /**
     * 统计退货申请
     * @param reportList 会员计数报表
     * @return 会员计数报表
     */
    private List<MemberTallyReportDO> statisticsReturnApplyTally(List<MemberTallyReportDO> reportList) {
        if (reportList == null) {
            reportList = new ArrayList<>();
        }
        List<AfterSaleReturnApplyStatisticsTallyVO> tallyVOList = returnGoodsDAO.getApplyStatisticsCount();
        List<StatisticsCountBO> statisticsList = tallyVOList.stream().map(r -> {
            StatisticsCountBO statisticsCountBO = new StatisticsCountBO();
            statisticsCountBO.setMemberId(r.getMemberId());
            statisticsCountBO.setRoleId(r.getRoleId());
            return statisticsCountBO;
        }).collect(Collectors.toList());

        // 补全统计数据
        List<MemberTallyReportDO> finalReportList = replenishData(reportList, statisticsList, "退货申请");

        finalReportList.forEach(p -> {
            // 如果报表数据为null，则实例化
            if (p.getTallyReport() == null) {
                p.setTallyReport(new MemberTallyReportBO());
            }
            AfterSaleReturnApplyTallyBO tallyBO = new AfterSaleReturnApplyTallyBO();
            AfterSaleReturnApplyStatisticsTallyVO tallyVO = tallyVOList.stream().filter(o -> o.getMemberId().equals(p.getMemberId()) && o.getRoleId().equals(p.getRoleId())).findFirst().orElse(null);
            if (null != tallyVO) {
                // 待提交退货申请单数
                tallyBO.setToBeCommitCount(tallyVO.getToBeCommitCount());
                // 待新增退货发货单数
                tallyBO.setToBeAddDeliveryCount(tallyVO.getToBeAddDeliveryCount());
                // 待确认物流单数
                tallyBO.setToBeAddLogisticsCount(tallyVO.getToBeAddLogisticsCount());
                // 待退货发货数
                tallyBO.setToBeDeliveryCount(tallyVO.getToBeDeliveryCount());
                // 待确认退货回单数
                tallyBO.setToBeConfirmReceiptCount(tallyVO.getToBeConfirmReceiptCount());
                // 待确认退款结果数
                tallyBO.setToBeConfirmRefundCount(tallyVO.getToBeConfirmRefundCount());
                // 待确认售后完成数
                tallyBO.setToBeConfirmCompleteCount(tallyVO.getToBeConfirmCompleteCount());
            }
            p.getTallyReport().setAfterSaleReturnApply(tallyBO);
        });

        return finalReportList;
    }

    /**
     * 统计退货处理
     * @param reportList 会员计数报表
     * @return 会员计数报表
     */
    private List<MemberTallyReportDO> statisticsReturnHandleTally(List<MemberTallyReportDO> reportList) {
        if (reportList == null) {
            reportList = new ArrayList<>();
        }
        List<AfterSaleReturnHandleStatisticsTallyVO> tallyVOList = returnGoodsDAO.getHandleStatisticsCount();
        List<StatisticsCountBO> statisticsList = tallyVOList.stream().map(r -> {
            StatisticsCountBO statisticsCountBO = new StatisticsCountBO();
            statisticsCountBO.setMemberId(r.getMemberId());
            statisticsCountBO.setRoleId(r.getRoleId());
            return statisticsCountBO;
        }).collect(Collectors.toList());
        // 补全统计数据
        List<MemberTallyReportDO> finalReportList = replenishData(reportList, statisticsList, "退货处理");

        finalReportList.forEach(p -> {
            // 如果报表数据为null，则实例化
            if (p.getTallyReport() == null) {
                p.setTallyReport(new MemberTallyReportBO());
            }
            AfterSaleReturnHandleTallyBO tallyBO = new AfterSaleReturnHandleTallyBO();
            AfterSaleReturnHandleStatisticsTallyVO tallyVO = tallyVOList.stream().filter(o -> o.getMemberId().equals(p.getMemberId()) && o.getRoleId().equals(p.getRoleId())).findFirst().orElse(null);
            if (null != tallyVO) {
                // 待提交
                tallyBO.setToBeCommitValifyCount(tallyVO.getToBeCommitValifyCount());
                // 待一级审核
                tallyBO.setToBeValifyStep1Count(tallyVO.getToBeValifyStep1Count());
                // 待二级审核
                tallyBO.setToBeValifyStep2Count(tallyVO.getToBeValifyStep2Count());
                // 待确认换货申请单数
                tallyBO.setToBeConfirmCount(tallyVO.getToBeConfirmCount());
                // 待新增换货入库单数
                tallyBO.setToBeAddStorageCount(tallyVO.getToBeAddStorageCount());
                // 待退货收货数
                tallyBO.setToBeReceiveCount(tallyVO.getToBeReceiveCount());
                // 待退款数
                tallyBO.setToBeRefundCount(tallyVO.getToBeRefundCount());
            }
            p.getTallyReport().setAfterSaleReturnHandle(tallyBO);
        });

        return finalReportList;
    }

    /**
     * 统计换货处理
     * @param reportList 会员计数报表
     * @return 会员计数报表
     */
    private List<MemberTallyReportDO> statisticsReplaceHandleTally(List<MemberTallyReportDO> reportList) {
        if (reportList == null) {
            reportList = new ArrayList<>();
        }
        List<AfterSaleReplaceHandleStatisticsTallyVO> tallyVOList = replaceGoodsDAO.getHandleStatisticsCount();
        List<StatisticsCountBO> statisticsList = tallyVOList.stream().map(r -> {
            StatisticsCountBO statisticsCountBO = new StatisticsCountBO();
            statisticsCountBO.setMemberId(r.getMemberId());
            statisticsCountBO.setRoleId(r.getRoleId());
            return statisticsCountBO;
        }).collect(Collectors.toList());
        // 补全统计数据
        List<MemberTallyReportDO> finalReportList = replenishData(reportList, statisticsList, "换货处理");

        finalReportList.forEach(p -> {
            // 如果报表数据为null，则实例化
            if (p.getTallyReport() == null) {
                p.setTallyReport(new MemberTallyReportBO());
            }
            AfterSaleReplaceHandleTallyBO tallyBO = new AfterSaleReplaceHandleTallyBO();
            AfterSaleReplaceHandleStatisticsTallyVO tallyVO = tallyVOList.stream().filter(o -> o.getMemberId().equals(p.getMemberId()) && o.getRoleId().equals(p.getRoleId())).findFirst().orElse(null);
            if (null != tallyVO) {
                // 待提交
                tallyBO.setToBeCommitValifyCount(tallyVO.getToBeCommitValifyCount());
                // 待一级审核
                tallyBO.setToBeValifyStep1Count(tallyVO.getToBeValifyStep1Count());
                // 待二级审核
                tallyBO.setToBeValifyStep2Count(tallyVO.getToBeValifyStep2Count());
                // 待确认换货申请单数
                tallyBO.setToBeConfirmCount(tallyVO.getToBeConfirmCount());
                // 待新增换货入库单数
                tallyBO.setToBeAddStorageCount(tallyVO.getToBeAddStorageCount());
                // 待退货收货数
                tallyBO.setToBeReceiveCount(tallyVO.getToBeReceiveCount());
                // 待待新增换货发货单数
                tallyBO.setToBeAddDeliveryCount(tallyVO.getToBeAddDeliveryCount());
                // 待待新增物流单数
                tallyBO.setToBeAddLogisticsCount(tallyVO.getToBeAddLogisticsCount());
                // 待换货发货数
                tallyBO.setToBeDeliveryCount(tallyVO.getToBeDeliveryCount());
                // 待确认换货回单数
                tallyBO.setToBeConfirmReceiptCount(tallyVO.getToBeConfirmReceiptCount());
            }

            p.getTallyReport().setAfterSaleReplaceHandle(tallyBO);
        });

        return finalReportList;
    }

    /**
     * 统计换货申请
     * @param reportList 会员计数报表
     * @return 会员计数报表
     */
    private List<MemberTallyReportDO> statisticsReplaceApplyTally(List<MemberTallyReportDO> reportList) {
        if (reportList == null) {
            reportList = new ArrayList<>();
        }
        List<AfterSaleReplaceApplyStatisticsTallyVO> tallyVOList = replaceGoodsDAO.getApplyStatisticsCount();
        List<StatisticsCountBO> statisticsList = tallyVOList.stream().map(r -> {
            StatisticsCountBO statisticsCountBO = new StatisticsCountBO();
            statisticsCountBO.setMemberId(r.getMemberId());
            statisticsCountBO.setRoleId(r.getRoleId());
            return statisticsCountBO;
        }).collect(Collectors.toList());

        // 补全统计数据
        List<MemberTallyReportDO> finalReportList = replenishData(reportList, statisticsList, "换货申请");

        finalReportList.forEach(p -> {
            // 如果报表数据为null，则实例化
            if (p.getTallyReport() == null) {
                p.setTallyReport(new MemberTallyReportBO());
            }
            AfterSaleReplaceApplyTallyBO tallyBO = new AfterSaleReplaceApplyTallyBO();
            AfterSaleReplaceApplyStatisticsTallyVO tallyVO = tallyVOList.stream().filter(o -> o.getMemberId().equals(p.getMemberId()) && o.getRoleId().equals(p.getRoleId())).findFirst().orElse(null);
            if (null != tallyVO) {
                // 待提交换货申请单数
                tallyBO.setToBeCommitCount(tallyVO.getToBeCommitCount());
                // 待新增退货发货单数
                tallyBO.setToBeAddDeliveryCount(tallyVO.getToBeAddDeliveryCount());
                // 待确认物流单数
                tallyBO.setToBeConfirmLogisticsCount(tallyVO.getToBeConfirmLogisticsCount());
                // 待退货发货数
                tallyBO.setToBeDeliveryCount(tallyVO.getToBeDeliveryCount());
                // 待确认退货回单数
                tallyBO.setToBeConfirmReceiptCount(tallyVO.getToBeConfirmReceiptCount());
                // 待新增换货入库单数
                tallyBO.setToBeAddStorageCount(tallyVO.getToBeAddStorageCount());
                // 待换货收货数
                tallyBO.setToBeReceiveCount(tallyVO.getToBeReceiveCount());
                // 待确认售后完成数
                tallyBO.setToBeConfirmCompleteCount(tallyVO.getToBeConfirmCompleteCount());
            }
            p.getTallyReport().setAfterSaleReplaceApply(tallyBO);
        });

        return finalReportList;
    }

    /**
     * 统计维修处理
     * @param reportList 会员计数报表
     * @return 会员计数报表
     */
    private List<MemberTallyReportDO> statisticsRepairHandleTally(List<MemberTallyReportDO> reportList) {
        if (reportList == null) {
            reportList = new ArrayList<>();
        }
        List<AfterSaleRepairHandleStatisticsTallyVO> tallyVOList = repairGoodsDAO.getHandStatisticsCount();
        List<StatisticsCountBO> statisticsList = tallyVOList.stream().map(r -> {
            StatisticsCountBO statisticsCountBO = new StatisticsCountBO();
            statisticsCountBO.setMemberId(r.getMemberId());
            statisticsCountBO.setRoleId(r.getRoleId());
            return statisticsCountBO;
        }).collect(Collectors.toList());
        // 补全统计数据
        List<MemberTallyReportDO> finalReportList = replenishData(reportList, statisticsList, "维修处理");
        finalReportList.forEach(p -> {
            // 如果报表数据为null，则实例化
            if (p.getTallyReport() == null) {
                p.setTallyReport(new MemberTallyReportBO());
            }
            AfterSaleRepairHandleTallyBO tallyBO = new AfterSaleRepairHandleTallyBO();
            AfterSaleRepairHandleStatisticsTallyVO tallyVO = tallyVOList.stream().filter(o -> o.getMemberId().equals(p.getMemberId()) && o.getRoleId().equals(p.getRoleId())).findFirst().orElse(null);
            if (null != tallyVO) {
                // 待提交
                tallyBO.setToBeCommitValifyCount(tallyVO.getToBeCommitValifyCount());
                // 待一级审核
                tallyBO.setToBeValifyStep1Count(tallyVO.getToBeValifyStep1Count());
                // 待二级审核
                tallyBO.setToBeValifyStep2Count(tallyVO.getToBeValifyStep2Count());
                // 待确认审核
                tallyBO.setToBeConfirmCount(tallyVO.getToBeConfirmCount());
            }
            p.getTallyReport().setAfterSaleRepairHandle(tallyBO);
        });

        return finalReportList;
    }

    /**
     * 统计维修申请
     * @param reportList 会员计数报表
     * @return 会员计数报表
     */
    private List<MemberTallyReportDO> statisticsRepairApplyTally(List<MemberTallyReportDO> reportList) {
        if (reportList == null) {
            reportList = new ArrayList<>();
        }
        List<AfterSaleRepairApplyStatisticsTallyVO> tallyVOList = repairGoodsDAO.getApplyStatisticsCount();
        List<StatisticsCountBO> statisticsList = tallyVOList.stream().map(r -> {
            StatisticsCountBO statisticsCountBO = new StatisticsCountBO();
            statisticsCountBO.setMemberId(r.getMemberId());
            statisticsCountBO.setRoleId(r.getRoleId());
            return statisticsCountBO;
        }).collect(Collectors.toList());
        // 补全统计数据
        List<MemberTallyReportDO> finalReportList = replenishData(reportList, statisticsList, "维修申请");
        finalReportList.forEach(p -> {
            // 如果报表数据为null，则实例化
            if (p.getTallyReport() == null) {
                p.setTallyReport(new MemberTallyReportBO());
            }
            AfterSaleRepairApplyTallyBO tallyBO = new AfterSaleRepairApplyTallyBO();
            AfterSaleRepairApplyStatisticsTallyVO tallyVO = tallyVOList.stream().filter(o -> o.getMemberId().equals(p.getMemberId()) && o.getRoleId().equals(p.getRoleId())).findFirst().orElse(null);
            if (null != tallyVO) {
                // 待提交
                tallyBO.setToBeCommitCount(tallyVO.getToBeCommitCount());
                // 待确认完成
                tallyBO.setToBeConfirmCompleteCount(tallyVO.getToBeConfirmCompleteCount());
            }
            p.getTallyReport().setAfterSaleRepairApply(tallyBO);
        });

        return finalReportList;
    }

    /**
     * 补全数据
     * @param reportList
     * @param statisticsList
     * @param name
     * @return
     */
    private List<MemberTallyReportDO> replenishData(List<MemberTallyReportDO> reportList, List<StatisticsCountBO> statisticsList, String name) {
        if (statisticsList == null) {
            logger.info("没有符合条件的{}计数统计数据", name);
            statisticsList = new ArrayList<>();
        }

        // 补全统计数据
        List<MemberTallyReportDO> finalReportList = reportList;
        statisticsList.stream().distinct().forEach(p -> {
            MemberTallyReportDO reportDO = finalReportList.stream()
                    .filter(o -> o.getMemberId().equals(p.getMemberId()) && o.getRoleId().equals(p.getRoleId()))
                    .findFirst().orElse(null);
            if (reportDO == null) {
                reportDO = new MemberTallyReportDO();
                reportDO.setMemberId(p.getMemberId());
                reportDO.setRoleId(p.getRoleId());
                finalReportList.add(reportDO);
            }
        });

        return finalReportList;
    }
}
